<template>
  <div class="list">
    <div
      class="item"
      :class="{ active: activeVal === item.dictValue }"
      v-for="(item, index) in listData"
      :key="item"
      @click="hadnleClick(item, index)">
      <SvgIcon
        class="svg-icon"
        :name="fileTypeIcon(item.dictValue)"
        :color="fileTypeIconColor(item.dictValue)"></SvgIcon>
      <span :style="{ color: fileTypeFontColor(item.dictValue) }">
        {{ item.dictLabel }}
      </span>
    </div>
  </div>
</template>

<script setup>
const props = defineProps({
  listData: Array,
  modelValue: String,
})
const emit = defineEmits(['update:modelValue'])

// const activeVal = computed(() => props.modelValue)
const activeVal = ref(null)
watch(
  () => props.modelValue,
  (newVal) => {
    activeVal.value = newVal
  },
  { immediate: true }
)

function fileTypeIconColor(val) {
  if (activeVal.value === val) {
    if (val === '1') {
      return 'var(--elp-color-danger)'
    } else if (val === '2') {
      return 'var(--elp-color-warning)'
    } else if (val === '3') {
      return 'var(--elp-color-primary)'
    } else if (val === '4') {
      return 'var(--elp-color-info-light-5)'
    }
  } else {
    return '#AEB6C2'
  }
}

function fileTypeIcon(val) {
  if (val === activeVal.value) {
    return 'task-worry-radioed'
  } else {
    return 'task-worry-radio'
  }
}
function fileTypeFontColor(val) {
  if (activeVal.value === val) {
    if (val === '1') {
      return 'var(--elp-color-danger)'
    } else if (val === '2') {
      return 'var(--elp-color-warning)'
    } else if (val === '3') {
      return 'var(--elp-color-primary)'
    } else if (val === '4') {
      return 'var(--elp-color-info-light-5)'
    }
  } else {
    return 'var(--elp-text-color-regular)'
  }
}

function hadnleClick(item, index) {
  activeVal.value = item.dictValue
  emit('update:modelValue', item.dictValue)
}
</script>

<style scoped lang="scss">
.list {
  display: flex;
  .item {
    margin-right: 30px;
    cursor: pointer;
    padding: 0 7px;
    font-size: 14px;
    // color: var(--elp-text-color-regular);
  }
  span {
    margin-left: 5px;
  }
  .active {
    background: var(--elp-color-info-light-9);
    border-radius: 4px;
  }
}
</style>
